package com.yincheng.oes.business.util.book.service.impl;

import com.yincheng.oes.business.util.book.dao.BookDao;
import com.yincheng.oes.business.util.book.dto.BookDTO;
import com.yincheng.oes.business.util.book.entity.BookDO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author yangsiyong
 * @version 1.0
 * @description: 书籍服务类
 * @date 2022/2/27 11:20 AM
 */
@Service
public class BookServiceImpl {
    @Autowired
    private BookDao bookDao;

    public List<BookDTO> selectAll() {
        List<BookDTO> list = new ArrayList<>();
        List<BookDO> bookDOS = bookDao.selectAll();
        if (CollectionUtils.isEmpty(bookDOS)) {
            return list;
        }
        list = bookDOS.stream().map(book -> {
            BookDTO bookDTO = new BookDTO();
            bookDTO.setBookId(book.getBookId());
            bookDTO.setBookName(book.getBookName());
            bookDTO.setMajorType(book.getMajorType());
            bookDTO.setSubjectType(book.getSubjectType());
            bookDTO.setTotalPage(book.getTotalPage());
            bookDTO.setYears(book.getYears());
            bookDTO.setTotalQuestion(book.getTotalQuestion());
            bookDTO.setValid(book.getValid());
            return bookDTO;
        }).collect(Collectors.toList());
        return list;
    }
}
